#include "mymainwindow.h"
#include <QWidget>
#include <QStackedWidget>

MyMainWindow::MyMainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    // 在此处可进行窗口初始化等操作，如设置窗口标题、添加菜单等
}

void MyMainWindow::resizeEvent(QResizeEvent *event)
{
    // 获取centralWidget
    QWidget *centralWidget = this->centralWidget();
    if (centralWidget) {
        // 获取centralWidget下的stackedWidget
        QStackedWidget *stackedWidget = centralWidget->findChild<QStackedWidget*>();
        if (stackedWidget) {
            // 遍历stackedWidget下的各个页面
            for (int i = 0; i < stackedWidget->count(); ++i) {
                QWidget *pageWidget = stackedWidget->widget(i);
                if (pageWidget) {
                    // 处理gamePage特殊情况
                    if (pageWidget->objectName() == "gamePage") {
                        QStackedWidget *sceneStackedWidget = pageWidget->findChild<QStackedWidget*>();
                        if (sceneStackedWidget) {
                            for (int j = 0; j < sceneStackedWidget->count(); ++j) {
                                QWidget *subPageWidget = sceneStackedWidget->widget(j);
                                subPageWidget->resize(event->size());
                            }
                        }
                    }
                    // 处理namePage特殊情况
                    else if (pageWidget->objectName() == "namePage") {
                        QStackedWidget *nameStackedWidget = pageWidget->findChild<QStackedWidget*>();
                        if (nameStackedWidget) {
                            for (int k = 0; k < nameStackedWidget->count(); ++k) {
                                QWidget *subPageWidget = nameStackedWidget->widget(k);
                                subPageWidget->resize(event->size());
                            }
                        }
                    }
                    else {
                        pageWidget->resize(event->size());
                    }
                }
            }
        }
    }
    // 调用父类的resizeEvent函数，确保默认行为也能执行
    QMainWindow::resizeEvent(event);
}
